package com.bw.intereptor;

import com.bw.entity.User;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class SessionIntereptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user = (User) request.getSession().getAttribute("user");
        if(user==null){
            response.sendRedirect("/user/tologin");
           /* request.setAttribute("error1","请先登录");
            request.getRequestDispatcher("/user/tologin").forward(request,response);*/
            return  false;
        }
        /*if(request.getRequestURL().equals("/user/tologin") || request.getRequestURL().equals("/user/login")){
            return true;
        }*/
        return true;


    }
}
